package com.xyw.code.platform.common.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.xyw.code.common.core.util.LongJsonDeserializer;
import com.xyw.code.common.core.util.LongJsonSerializer;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 菜单权限表
 * </p>
 *
 * @author xyw
 * @since 2020-02-17
 */
@TableName("sys_menu")
@Data
public class SysMenu extends Model<SysMenu> {

    private static final long serialVersionUID = 1L;

    /**
     * 菜单ID
     */
    @TableId(type = IdType.ID_WORKER)
    @JsonDeserialize(using = LongJsonDeserializer.class)
    @JsonSerialize(using = LongJsonSerializer.class)
    private Long id;
    /**
     * 访问请求的地址
     */
    private String url;
    /**
     * 菜单名称
     */
    private String name;
    /**
     * 菜单权限标识
     */
    private String perms;
    /**
     * 前端跳转URL
     */
    private String path;
    /**
     * post delete get put
     */
    private String method;

    /**
     * 菜单组件
     */
    private String component;
    /**
     * 父菜单ID
     */
    @TableField("parent_id")
    @JsonDeserialize(using = LongJsonDeserializer.class)
    @JsonSerialize(using = LongJsonSerializer.class)
    private Long parentId;
    /**
     * 图标
     */
    private String icon;
    /**
     * 排序
     */
    private Integer sort;
    /**
     * 菜单类型 （类型   0：目录   1：菜单   2：按钮）
     */
    private Integer type;
    /**
     * 逻辑删除标记(0--正常 1--删除)
     */
    @TableField("del_flag")
    private Integer delFlag;
    /**
     * 是否为外链(0--外链 1--本地)
     */
    @TableField("is_frame")
    private Integer isFrame;
    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;
    /**
     * 更新时间
     */
    @TableField("update_time")
    private Date updateTime;


    /**
     * 非数据库字段
     * 父菜单名称
     */
    @TableField(exist = false)
    private String parentName;

    /**
     * 非数据库字段
     * 菜单等级
     */
    @TableField(exist = false)
    private Integer level;

    /**
     * 非数据库字段
     * 子菜单
     */
    @TableField(exist = false)
    private List<SysMenu> children;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @Override
    public String toString() {
        return "SysMenu{" +
        ", id=" + id +
        ", name=" + name +
        ", perms=" + perms +
        ", path=" + path +
        ", component=" + component +
        ", parentId=" + parentId +
        ", icon=" + icon +
        ", sort=" + sort +
        ", type=" + type +
        ", delFlag=" + delFlag +
        ", isFrame=" + isFrame +
        ", createTime=" + createTime +
        ", updateTime=" + updateTime +
        "}";
    }
}
